package il.ac.technion.cs236700.utils.visitor;



/**
 * Implementing Visitor Design Pattern.
 * SimpleVisitor is a parameterized abstraction over foreach loop.
 * Uses {@link Action} as the action to take on each item. 
 * @authors Regev Azriel & Sharon ronen
 *
 * @param <T> - the type of each item in the iterable parameter
 */
public class SimpleVisitor <T> {

	protected final Action<T> visitor;
	protected Iterable<T> iterable;

	public SimpleVisitor(Iterable<T> iterable,Action<T> visitor){		
		this.visitor = visitor;
		this.iterable = iterable;
	}
	
	public SimpleVisitor<T> go(){
		for (T item : iterable) {
			visitor.visit(item);
		}
		return this;
	}
	
}
